<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        table{
            border-spacing: 10px;
        }
        td{
            border: 1px solid #686868;
            text-align: center;
            width: 60px;
        }
    </style>
</head>

<body>

</body>
<script>
    //1.有一个数组 list=["a","b","c","d","e","f"] 随机取四个元素,放到新数组中,再拼接形成字符串 (可以重复)

     list=["a","b","c","d","e","f"];
     var news = [];
     // debugger;
     for(i = 0; i < 4 ; i++){
         sum = Math.floor(Math.random() * list.length);
         console.log(sum);
         var result = news.push(list[sum]);
         console.log(result);
     }
     document.write(news + "<br>");

    // 1.1  要求随机的四个元素 不重复 
    
    var cf = [];
   //  debugger;
    for(i = 0; i < 4 ; i++){
        sum = Math.floor(Math.random() * list.length);
       //  console.log(sum);
        var result = cf.push(list[sum]);
        list.splice(sum,1);
        console.log(list);
        console.log(result);
    }
    document.write(cf + "<br>");

    /* 2.数组去重
      有一个数组 var arr = [ 1, 2, 3, 3, 2, 1, 3, 1, 2, 1, 3, 2]  去除数组中的重复项=> [1,2,3] */

     var arr = [ 1, 2, 3, 3, 2, 1, 3, 1, 2, 1, 3, 2];
    //  debugger;
     for(i = 0; i < arr.length ; i++){
         for(j = i + 1; j < arr.length ; j++){
             if(arr[i] == arr[j]){
                 var qu = arr.splice(j,1);
                 console.log(arr);
                 j--;
             }
         }
     }
     document.write(arr + "<br>");

    /* 3.有一个二维数组
        var list = [
            ["张三", 55, 66, 77],
            ["李四", 67, 89, 90],
            ["王五", 96, 50, 87],
        ]
    根据二维数组  动态生成表格    => 通过中间变量 二维转一维

    var item = list[0];   // ["张三", 55, 66, 77]
    item[0] */

    var list = [
        ["张三", 55, 66, 77],
        ["李四", 67, 89, 90],
        ["王五", 96, 50, 87],
    ];
    var biao = list.unshift(["姓名","语文","数学","英语"]);
    console.log(biao);

    document.write("<table>");

    for (j = 0; j < list.length; j++) {
        var item = list[j];
        document.write("<tr>");
        for (i = 0; i < item.length; i++) {
            document.write("<td>");
            document.write(item[i]);
            document.write("</td>");
        }
        document.write("</tr>");
    }

    document.write("</table>");
</script>

</html>